import { createRouter, createWebHistory } from "vue-router";
import store from "@/store/store";
import Home from "../views/home/HomeView.vue";
import Log from "../views/log/IncomeLog.vue";
import InviteLog from "../views/log/InviteLog.vue";
import Mining from "../views/mining/MiningView.vue";
import Introduce from "../views/introduce/IntroduceView.vue";

const router = createRouter({
  history: createWebHistory(),
  // history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      name: "home",
      component: Home,
      meta: {
        title: "UKEY NETWORK",
        keepAlive: true
      },
    },
    {
      path: "/log",
      name: "log",
      component: Log,
      meta: {
        title: "收益记录",
      },
    },
    {
      path: "/inviteLog",
      name: "inviteLog",
      component: InviteLog,
      meta: {
        title: "邀请记录",
      },
    },
    {
      path: "/introduce",
      name: "introduce",
      component: Introduce,
      meta: {
        title: "项目介绍",
      },
    },
    {
      path: "/mining",
      name: "mining",
      component: Mining,
      meta: {
        title: "UKey",
      },
    },
  ],
});
router.beforeEach((to, from, next) => {
  console.log(to, from, "to,from");
  if (to.href === "/introduce") {
    store.dispatch("setCheckoutValue", 4);
  } else if (to.href === "/") {
    store.dispatch("setCheckoutValue", 1);
  }
  next();
});

export default router;
